package com.platform.qujia.config;

import com.google.common.collect.Lists;
import com.platform.qujia.interceptor.GlobalContextInterceptor;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.List;

/**
 * <p>
 * 服务上下文拦截器配置类
 * </p>
 *
 * @author zph
 * @since 2022-07-11
 */
@Configuration
//@ConfigurationProperties(prefix = "context.interceptor.config")
public class ContextInterceptorConfig implements WebMvcConfigurer {

    private List<String> excludePathPatterns = Lists.newArrayList();

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(contextInterceptor()).addPathPatterns("/**").excludePathPatterns(excludePathPatterns).order(10);
    }

    @Bean
    public GlobalContextInterceptor contextInterceptor() {
        return new GlobalContextInterceptor();
    }

    public List<String> getExcludePathPatterns() {
        return excludePathPatterns;
    }

    public void setExcludePathPatterns(List<String> excludePathPatterns) {
        this.excludePathPatterns = excludePathPatterns;
    }
}